package com.qixiaobao.web.controller.direct.settle;

import com.qixiaobao.common.annotation.Log;
import com.qixiaobao.common.core.page.TableDataInfo;
import com.qixiaobao.common.enums.BusinessType;
import com.qixiaobao.common.utils.easyExcel.EasyExcelUtil;
import com.qixiaobao.direct.settle.domain.dto.DirectSettleDTO;
import com.qixiaobao.direct.settle.domain.vo.DirectWaitPayVO;
import com.qixiaobao.direct.settle.domain.vo.DirectWaitSettleVO;
import com.qixiaobao.direct.settle.service.IDirectSettleService;
import com.qixiaobao.system.domain.dto.PersonDTO;
import com.qixiaobao.web.controller.core.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description 直投结算管理
 * @Author yangxm
 * @Date 2025/6/26 11:28
 */
@Slf4j
@RestController
@RequestMapping("/directSettle")
public class DirectSettleController extends BaseController {


    @Autowired
    private IDirectSettleService directSettleService;


    /**
     * @Description 待结算列表
     * @Author yangxm
     * @Date 2025/6/26 11:51
     * @param directSettleDTO
     * @return com.qixiaobao.common.core.page.TableDataInfo
     */
    @RequestMapping("/wait/settle/list")
    public TableDataInfo waitSettleList(DirectSettleDTO directSettleDTO){
        directSettleDTO.setNoPermissionSupplyIdList(checkPermission());
        startPage();
        return getDataTable(directSettleService.selectWaitSettlementList(directSettleDTO));
    }

    /**
     * @Description 待结算列表导出
     * @Author yangxm
     * @Date 2025/6/26 11:51
     * @param directSettleDTO
     * @param response
     * @return void
     */
    @Log(title = "直接结算管理-待结算", businessType = BusinessType.EXPORT)
    @RequestMapping("/wait/settle/export")
    public void waitSettleExport(DirectSettleDTO directSettleDTO, HttpServletResponse response){
        directSettleDTO.setNoPermissionSupplyIdList(checkPermission());
        List<DirectWaitSettleVO> list = directSettleService.selectWaitSettlementList(directSettleDTO);
        try {
            EasyExcelUtil.writeExcel(response, list, DirectWaitSettleVO.class, "直接结算管理待结算", "sheet1");
        } catch (IOException e) {
            log.error("直接结算管理待结算导出异常：", e);
            throw new RuntimeException("直接结算管理待结算导出异常：" + e.getMessage());
        }
    }

    /**
     * @Description 待结算人员列表
     * @Author yangxm
     * @Date 2025/6/26 11:51
     * @param personDTO
     * @return com.qixiaobao.common.core.page.TableDataInfo
     */
    @GetMapping("/wait/settle/person/list")
    public TableDataInfo waitSettlePersonList(PersonDTO personDTO){
        startPage();
        return getDataTable(directSettleService.selectWaitSettlePersonList(personDTO));
    }

    /**
     * @Description 待支付 列表
     * @Author yangxm
     * @Date 2025/6/26 16:00
     * @param directSettleDTO
     * @return com.qixiaobao.common.core.page.TableDataInfo
     */
    @GetMapping("/wait/pay/list")
    public TableDataInfo waitPayList(DirectSettleDTO directSettleDTO){
        directSettleDTO.setNoPermissionSupplyIdList(checkPermission());
        startPage();
        return getDataTable(directSettleService.selectWaitPayList(directSettleDTO));
    }

    /**
     * @Description 待支付列表导出
     * @Author yangxm
     * @Date 2025/6/26 16:00
     * @param directSettleDTO
     * @param response
     * @return void
     */
    @Log(title = "直接结算管理-待支付", businessType = BusinessType.EXPORT)
    @GetMapping("/wait/pay/export")
    public void waitPayExport(DirectSettleDTO directSettleDTO, HttpServletResponse response){
        directSettleDTO.setNoPermissionSupplyIdList(checkPermission());
        List<DirectWaitPayVO> list = directSettleService.selectWaitPayList(directSettleDTO);
        try {
            EasyExcelUtil.writeExcel(response, list, DirectWaitPayVO.class, "直接结算管理待支付", "sheet1");
        } catch (IOException e) {
            log.error("直接结算管理待支付导出异常：", e);
        }
    }

    /**
     * @Description 已结算列表
     * @Author yangxm
     * @Date 2025/7/15 9:55
     * @param directSettleDTO
     * @return com.qixiaobao.common.core.page.TableDataInfo
     */
    @GetMapping("/settled/list")
    public TableDataInfo settledList(DirectSettleDTO directSettleDTO){
        directSettleDTO.setNoPermissionSupplyIdList(checkPermission());
        startPage();
        return getDataTable(directSettleService.selectSettledList(directSettleDTO));
    }
}
